set more off

local Y finesandforfeitspcp pctfinesandforfeits pctblack pctblackgov

#delimit;
local X 
	totalrevownsourcespcp pcttotaltax pcttotalig
	population popdensity incomepcp pctba pct65plus H pcthisp herf pctforeign
	crimepcp totalpolicepcp dem ngovspcp netmigration 
	;
#delimit cr

local j = 1
foreach dataset in dataset dataset35k {

	use `dataset', clear
	
	replace pctblack = exp(pctblack) - 1
	
	replace income = . if income <= 0 & !mi(income)

	label variable pctblack "Percent black population"
	label variable pctblackgov "Percent black city council"
	label variable population "Population"
	label variable popdensity "Population per sq. mi."
	label variable finesandforfeitspcp "Fines revenue per capita"
	label variable pctfinesandforfeits "Fines as share of local revenue"
	replace crimepcp = crimepcp*100000
	label variable crimepcp "Crimes per 100k"
	replace herf = herf * 100
	replace H = H * 100
	label variable herf "Herfindahl x100"
	label variable H "Segregation x100"

	eststo clear

	estpost summarize `Y' `X'

	#delimit;

	esttab
		using "tableA8_`j'.tex"
		,
			replace
			cells("
				count(fmt(%20.00fc)) 
				mean(fmt(%20.00fc)) 
				sd(fmt(%20.00fc)) 
				min(fmt(%20.00fc)) 
				max(fmt(%20.00fc))
			") 
			noobs
			label
			nomtitles
			nonum
			collabels(Count Mean "Std. Dev." Min. Max.)
			booktabs
			width(\textwidth)
			;

	#delimit cr
		
	local j = `j' + 1
	
}
